#include <iostream>

using namespace std;
#define int long long
const int N = 1e5 + 10;
int a[N];
int n , x;
signed main()
{
    cin >> n >> x;
    int sum = 0;
    for(int i = 1;i <= n;i ++)
    {
        cin >> a[i];
        int d = a[i] + a[i - 1] - x;
        if(d > 0)
        {
            sum += d;
            a[i] = x - a[i - 1];
        }
    }
    cout << sum << endl;
    return 0;
}